<template>
  <u-container-layout>
    <zlrt-table :p="ctx">
      <template #before>
        <zlrt-search :p="ctx">
          <!-- <template #warehouseName>
            <el-select v-model="ctx.filter.warehouseId">
              <el-option v-for="item in warehouseOptions" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </template> -->
        </zlrt-search>
        <div class="tool-bar">
          <el-button type="danger" v-hasPermit="['wms:goodsProject:del']" icon="Delete" :disabled="!ctx.selected.length"
            @click="ctx.batchDelete()">
            批量删除
          </el-button>
          <span style="float:right">
            <el-button type="success" v-hasPermit="['wms:goodsProject:list']" :loading="ctx.exportLoading" icon="Download"
              @click="ctx.export()">
              导出
            </el-button>
            <el-button type="primary" v-hasPermit="['wms:goodsProject:save']" :loading="ctx.exportLoading" icon="Plus"
              @click="ctx.showEdit()">
              新增
            </el-button>
          </span>
        </div>
      </template>
      <template #type="scope">
        {{ ctx.other.getTypeName(scope.row.type) }}
      </template>
      <template #operation="scope">
        <!-- <el-button type="primary" v-hasPermit="['wms:goodsProject:save']" link size="small" icon="Edit"
          @click="ctx.showEdit(scope.row)">
          编辑
        </el-button> -->
        <el-button v-hasPermit="['wms:goodsProject:del']" type="danger" link size="small" icon="Delete"
          @click="ctx.del(scope.row.id)">
          删除
        </el-button>
      </template>
      <template #after>
        <el-dialog v-model="ctx.editVisible" :title="ctx.editAction + ctx.title" width="1100px" append-to-body top="3vh"
          :close-on-click-modal="false" @close="ctx.closeEdit()">
          <el-form :ref="(e) => ctx.formRef = e" :model="ctx.editData" :rules="ctx.rules" v-loading="ctx.editLoading"
            label-width="120px" class="demo-ruleForm">
            <el-form-item label="类型" prop="type">
              <el-select v-model="ctx.editData.type" filterable placeholder="请选择类型"
                style="width: 100%;">
                <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="原始项目" prop="name">
              <el-select v-model="ctx.editData.name" filterable placeholder="请选择原始项目"
                style="width: 100%;">
                <el-option v-for="item in projectOptions" :key="item.id" :label="item.name" :value="item.name">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="目标项目" prop="nameNew">
              <el-select v-model="ctx.editData.nameNew" filterable placeholder="请选择目标项目"
                style="width: 100%;">
                <el-option v-for="item in projectOptions" :key="item.id" :label="item.name" :value="item.name">
                </el-option>
              </el-select>
            </el-form-item>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" size="small" icon="Plus" @click="ctx.other.addGoods">
                  添加
                </el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" icon="delete" size="small" @click="ctx.other.delGoods" :disabled="!ctx.editData.orderGoodsList || !ctx.editData.orderGoodsList.length">删除</el-button>
              </el-col>
            </el-row>
            <el-divider content-position="center">物料明细</el-divider>
            <el-table :data="ctx.editData.orderGoodsList" style="width: 100%;margin-top: 10px;" @selection-change="ctx.other.handleGoodsSelectionChange">
              <el-table-column type="selection" width="55" />
              <el-table-column prop="skuName" label="物料名称" width="500">
                <template #default="scope">
                    <el-select
                    style="width: 470px;"
                    v-model="scope.row.skuName"
                    filterable
                    remote
                    reserve-keyword
                    :remote-method="getGoodsList"
                    :loading="loading"
                    @change="handleSkuChange($event, scope)"
                  >
                    <el-option
                      v-for="item in goodsOptions"
                      :key="item.id"
                      :label="item.skuName"
                      :value="item.skuName"
                    >
                    </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column prop="barCode" label="物料编码" width="120"></el-table-column>
              <el-table-column prop="specification" label="规格型号" width="200">
                <template #default="scope">
                  {{ scope.row.specification || '-' }}
                </template>
              </el-table-column>
              <el-table-column prop="number" label="数量" width="100">
                <template #default="scope">
                  <el-input style="width: 100%;" v-model.trim="scope.row.number" />
                </template>
              </el-table-column>
              <el-table-column prop="unit" label="单位">
                <template #default="scope">
                  {{ scope.row.unit || '-' }}
                </template>
              </el-table-column>
            </el-table>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="ctx.editVisible = false">取消</el-button>
              <el-button type="primary" :loading="finishLoading" @click="ctx.other.save()">确定</el-button>
            </span>
          </template>
        </el-dialog>
      </template>
    </zlrt-table>
  </u-container-layout>
</template>

<script lang="ts" src="./goodsProject" />

<style lang="scss" scoped>

</style>
